﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//................
using QLKTX1._0.DTO;
using QLKTX1._0.DB;
using System.Data.SqlClient;
using System.Data;
//.................
namespace QLKTX1._0.DAO
{
    class KhoaDAO
    {
        public static List<KhoaDTO> dsKhoa()
        {

            List<KhoaDTO> dsKhoa = new List<KhoaDTO>();

            ConnectDB con = new ConnectDB();
            DataTable dt = con.getDataTable("SELECT * FROM Khoa order by (tenKhoa) asc");

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                KhoaDTO k = new KhoaDTO();

                k.MaKhoa  = Int32.Parse(dt.Rows[i]["maKhoa"].ToString());
                k.TenKhoa  = dt.Rows[i]["tenKhoa"].ToString();

                dsKhoa.Add(k);//them vao list  doi tuong TenPhong vao list
            }
            return dsKhoa;
        }
        //ham them ten phong
        public static bool themKhoa(KhoaDTO khoa)
        {
            ConnectDB con = new ConnectDB();
            return con.executeQuery("INSERT INTO Khoa(tenKhoa) VALUES('" + khoa.TenKhoa + "')");
        }
        //ham xoa ten phong
        public static bool xoaKhoa(KhoaDTO khoa)
        {
            ConnectDB con = new ConnectDB();
            return con.executeQuery("DELETE FROM Khoa WHERE maKhoa='" + khoa.MaKhoa + "' ");
        }
        //ham cap nhat ten phong
        public static bool capNhatKhoa(KhoaDTO khoa)
        {
            ConnectDB con = new ConnectDB();
            return con.executeQuery("UPDATE Khoa set tenKhoa='" + khoa.TenKhoa + "' WHERE maKhoa='" + khoa.MaKhoa + "' ");
        }
    }
}
